<?php
namespace app\admin\controller;

use app\model\admin;
use think\Request;
use think\Session;
use think\Controller;

class Message extends Controller
{
    //留言列表
    public function index()
    {
        $dao = new \app\model\admin\Message();
        $where=[];
        $lists = $dao->get_message_lists($where,$sort='id desc',$paginate=10);
        $this->assign('lists', $lists);
        return $this->fetch('message/index');
    }
    //留言详情
    public function message_detail()
    {
        $dao = new \app\model\admin\Message();
        if($this->request->get("id")<1){
            return json(['status'=>2,'data'=>(object)[],'msg'=>'参数错误!']);
        }else{
           $id = $this->request->get("id");
        }
        $message_detail = $dao->message_detail($id);
        if(empty($message_detail)){
            return json(['status'=>1,'data'=>(object)[],'msg'=>'暂无数据!']);
        }else{
            if($message_detail['time']!==null){
                $message_detail['time'] = date('Y-m-d H:i:s',$message_detail['time']);
            }
            return json(['status'=>0,'data'=>$message_detail,'msg'=>'操作成功!']);
        }
    }
    //留言删除
    public function message_delete()
    {
        $dao = new \app\model\admin\Message();
        if($this->request->get("id")<1){
            return json(['status'=>2,'data'=>(object)[],'msg'=>'参数错误!']);
        }else{
            $id = $this->request->get("id");
        }
        $message_delete = $dao->delete_message([$id]);
        if($message_delete == 0){
            return json(['status'=>3,'data'=>(object)[],'msg'=>'删除失败!']);
        }else{
            return json(['status'=>0,'data'=>$message_delete,'msg'=>'操作成功!']);
        }
    }
}


